<!DOCTYPE html>
<html>

	<head lang="en">
		<title>骡窝日报</title>
		<meta charset="utf-8" />
		<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
		<link rel="stylesheet" href="/js/bootstrap/css/bootstrap.min.css">
		<script src="/js/jquery/jquery.min.js"></script>
		<script src="/js/bootstrap/js/bootstrap.js"></script>
		<link rel="stylesheet" href="/css/font/css/font-awesome.min.css" />
		<link rel="stylesheet" href="/css/reset.css" />
		<link rel="stylesheet" href="/css/news.css" />
		<script src="/js/plugins/jrender/jrender.js"></script>
		<link rel="stylesheet" href="/js/plugins/jquery-confirm/css/jquery-confirm.css">
		<script src="/js/plugins/jquery-confirm/js/jquery-confirm.js"></script>
		<script src="/js/common.js"></script>
		<link rel="stylesheet" href="/js/plugins/dialog/dialog.css">
		<script src="/js/plugins/dialog/dialog.min.js"></script>
		<script src="/js/common.js"></script>

	</head>

	<body>

	<div class="search-head">
		<div class="row nav-search">
			<div class="col-2">
				<a href="index.html">
					<span><i class="fa fa-chevron-left fa-2x"></i></span>
				</a>
			</div>
			<div class="col-10">
				<div class="input-group-sm search">
					<input class="form-control searchBtn"  placeholder="根据标题搜索日报">
				</div>
			</div>
		</div>
	</div>

		<div class="container news">
		
			<div class="news">
				<h6 class="news-title">更多精彩日报 </h6>

				<div class="row" id="newsPage" render-loop="list">
					<div class="col-6" >

						<p>
						<a render-key="list.id" render-fun="handle"  data-id="2">
							<img class="rounded" width="170"   render-src="list.coverUrl">
						<div class="caption">
								<p render-html="list.title"></p>
						</div>
						</a>


					<div id="collection">
						<button  render-value="id" class="btn btn-success ibtn" id="followBtn">收藏</button>
					</div>

						</p>
					</div>

				</div>
			</div>
		</div>



<script>
	$(function(){






	   //渲染更多界面
        $.get("/dailyDetails/else", {state: 3}, function (data) {

            $(".news").renderValues({list: data}, {
                handle: function (ele, val) {
                    ele.href = "/newsContent.html?id=" + val;
                }
            });

            var state = true;

                $("#newsPage").on("click","button",function () {
                    //判断用户是否登入
                    if (getUser()) {
                        $.post("/dailys/")
                        if (state) {
                            $(this).html("已收藏");
                            state=false;
                        }else{
                            $(this).html("收藏");
                            state=true;
                        }

                    }else{
                        location.href="login.html";
                    }

                });




        });


        var currentPage = 1; //当前页
        var dailyDetails; //当前页面的日报
        var pages; //总页数

        //高级查询
        //设置查询框点击事件
        $(".searchBtn").click(function () {
            currentPage=1;
        });
        //设置查询框的值改变事件
        //发送ajax请求获取筛选过的日报
        $(".searchBtn").change(function () {
            var val= $(this).val();
            $.get("/dailyDetails/",{keyword:val},function (data) {
                console.log(data);
                renderView(data);
                dailyDetails=data.list;
				 pages=data.pages;
            });
        })  ;

        //发送ajax请求获取已发布日报
        $.get("/dailyDetails", function (data) {
            console.log(data);
            //渲染界面
            renderView(data);
            dailyDetails = data.list;
            console.log(dailyDetails);
            pages = data.pages;
            console.log(pages);
        });

        //设置窗口的滚动事件
        $(window).scroll(function () {
            //取出当前查询框的值
            var keyword= $(".searchBtn").val();
            if (isFull()) {
                //判断当前不是最后一页
                if (currentPage < pages) {
                    $.get("/dailyDetails", {currentPage: ++currentPage,keyword:keyword}, function (data) {
                        //叠加之前的日报数据
                        $.merge(dailyDetails, data.list);
                        //再次渲染界面
                        renderView({list: dailyDetails});
                    });
                } else {
                    //提示到底了
                    $(document).dialog({
                        type : "notice",
                        infoText: "没有下一页,到底了",
                        autoClose: 1500,
                        position: "bottom"
                    });
                }
            }
        });

        function renderView(data) {
            $(".news").renderValues(data, {
                handle: handle
            })
        }

        function handle(ele, val) {
            ele.href = "/newsContent.html?id="+val;
        }

    });


</script>
</body>
</html>